﻿namespace ChinaUnicom.Tasks
{
    using ChinaUnicom.Schedule;
    using System;
    using System.Windows;
    using System.Net;
    using System.IO;

    internal class CodeImageTask : ITask
    {
        public Stream Stream { get; private set; }

        public CodeImageTask()
        {
        }

        public void Start()
        {
            if (Started != null)
            {
                Started(this, EventArgs.Empty);
            }

            Factory.Operation.RequestCodeImage(ss =>
            {
                if (ss.StatusCode == HttpStatusCode.OK)
                {
                    Stream = ss.ResponseStream;
                    if (Completed != null)
                    {
                        Completed(this, EventArgs.Empty);
                    }
                }
            });
        }

        public int Pending { get { return 0; } }

        public event EventHandler Completed;


        public event EventHandler Started;
    }
}
